const KoaRouter = require("@koa/router");
const { verifyAuth } = require("../middleware/loginMiddleware.js");
const {
	create,
	getList,
	detail,
	update,
	deleteCon,
	addLabels,
} = require("../controller/momentControll.js");
const {
	verifyMomentPermission, verifyPermission,
} = require("../middleware/permissionMiddleware.js");
const { verifyLabelExists } = require("../middleware/labelMiddleware.js");



const momentRouter = new KoaRouter({ prefix: "/moment" });

// 发表动态接口  需要用户登录 先验证是否登录
momentRouter.post("/", verifyAuth, create);

// 获取动态列表 无需登录
momentRouter.get("/list", getList);

// 获取某条动态详情
momentRouter.get("/detail/:momentId", detail);

// 修改某条数据  先验证是否登录  然后模拟登录鉴权   最后执行修改
momentRouter.patch(
	"/update/:momentId",
	verifyAuth,
	verifyPermission,
	update
);


// 删除动态 登录鉴权 
// verifyMomentPermission 只对moment做了鉴权
// verifyPermission 封装后的鉴权  注意需要鉴权的接口 momentId  都是这种格式***Id
momentRouter.delete(
	"/delete/:momentId",
	verifyAuth,
	verifyPermission,
	deleteCon
);


// 为某条动态添加标签
momentRouter.post('/:momentId/labels', verifyAuth , verifyPermission ,verifyLabelExists , addLabels )


module.exports = momentRouter;
